<template>
  <div class="apptop" :class="{actvie:showMenu}">
      <span class="menu" @click="SET_SHOW_MENU()">

      </span>
       {{titleText}}
      <span class="login" @click="exit">

      </span>
  </div>
</template>

<script>
  import { mapMutations, mapState } from 'vuex'
  export default {
    name: 'appTop',
    data () {
      return {
        titleText: '全部',
        titleWord: 'all'
      }
    },
    computed: {
      ...mapState(['showMenu', 'userInfo'])
    },
    mounted: function () {
      this.$nextTick(function () {
        this.isStatus()
      })
    },
    methods: {
      ...mapMutations(['SET_SHOW_MENU', 'SET_USER_INFO']),
      exit () {
        this.titleWord = this.$route.query.tab
        if (!this.userInfo) {
          this.SET_USER_INFO()
          this.$message({
            showClose: true,
            message: '退出成功',
            type: 'success'
          })
        } else {
          this.$message({
            showClose: true,
            message: '您还未登录',
            type: 'error'
          })
        }
      },
      isStatus () {
        if (this.$route.query.tab) {
          this.titleWord = this.$route.query.tab
          switch (this.titleWord) {
            case 'all':
              this.titleText = '全部'
              break
            case 'good':
              this.titleText = '精华'
              break
            case 'share':
              this.titleText = '分享'
              break
            case 'ask':
              this.titleText = '问答'
              break
            case 'job':
              this.titleText = '招聘'
              break
            default:
              this.titleText = '全部'
              break
          }
        } else {
          if (this.$route.params.id) {
            this.titleText = '主题'
          }
        }
      }
    },
    watch: {
      '$route' () {
        this.isStatus()
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
  .apptop{
    height:0.8rem;
    border-bottom:1px solid #E4E4E4;
    box-shadow:0 -2px 10px 1px rgba(0,0,0,0.5);
    line-height: 0.8rem;
    text-align: center;
    position: relative;
    transition: 0.3s;
    .menu{
      height:0.4rem;
      width:0.4rem;
      position: absolute;
      top:0.2rem;
      left:0.36rem;
      background: url("../assets/meun.png") no-repeat;
      background-size: contain;
    }
    .login{
      height:0.4rem;
      width:0.4rem;
      position: absolute;
      top:0.2rem;
      right:0.36rem;
      background: url("../assets/login.png") no-repeat;
      background-size: contain;
    }
    &.actvie{
      -webkit-transform:translateX(50%);
      -moz-transform: translateX(50%);
      -ms-transform: translateX(50%);
      -o-transform: translateX(50%);
      transform: translateX(50%);
    }
  }
  .show{
    display: none;
  }
</style>
